<?php

namespace Wzbmail\Yii2Api\response\wrapper;

class ApiWrapper
{
    const DEFAULT_CODE = 0;

    public bool $success = true;
    public string $message = '';
    public int $code = self::DEFAULT_CODE;
    public array $data = [];

    public function setSuccess(bool $success): static
    {
        $this->success = $success;
        return $this;
    }

    public function setMessage(string $message): static
    {
        $this->message = $message;
        return $this;
    }

    public function setCode(int $code): static
    {
        $this->code = $code;
        return $this;
    }

    public function setData(array $data): static
    {
        $this->data = $data;
        return $this;
    }

    public function originData(mixed $data)
    {
        return $data;
    }

    public function error(string $message = '', array $data = [], int $code = self::DEFAULT_CODE): static
    {
        return $this->setMessage($message)->setCode($code)->setData($data)->setSuccess(false);
    }

    public function success(string $message = '', array $data = [], int $code = self::DEFAULT_CODE): static
    {
        return $this->setMessage($message)->setCode($code)->setData($data)->setSuccess(true);
    }
}